package cn.itsource.ymcc.consumer;

import cn.itsource.ymcc.constant.Constants;
import cn.itsource.ymcc.constant.ConstantsOrderMq;
import cn.itsource.ymcc.service.IPayOrderService;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

@Slf4j
@Component
//consumerGroup = 定义组
//topic = 主题
//selectorExpression = tag
@RocketMQMessageListener(
        consumerGroup = "PayOutTimeConsumer",
        topic = ConstantsOrderMq.TOPIC_COURSE_ORDER_DEALY,
        selectorExpression = ConstantsOrderMq.TAGS_COURSE_ORDER_DEALY
)
public class PayOutTimeConsumer implements RocketMQListener<MessageExt> {
    @Autowired
    private IPayOrderService service;
    @Override
    public void onMessage(MessageExt messageExt) {
        try {
            //得到消息
            byte[] body = messageExt.getBody();
            //转为字符串  -- json字符串
            String orderNo = new String(body, Constants.UTF8);
            service.payOutTime(orderNo);
            log.info("支付单超时修改成功");
        } catch (UnsupportedEncodingException e) {
            log.info("支付单时修改失败");
            e.printStackTrace();
        }
    }
}
